﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace YJKDataLookAfter
{
	public partial class DlgMessageBox : System.Windows.Forms.Form
	{
		public DlgMessageBox(DbUser user)
		{
			this.InitializeComponent();
			foreach (DbUserMessage dbUserMessage in user.GetMessage())
			{
				this.dataGridView1.Rows.Add(new object[]
				{
					false,
					dbUserMessage.Sender.Name,
					dbUserMessage.Date.ToString(),
					dbUserMessage.Text,
					dbUserMessage.Id,
					dbUserMessage.StatusString
				});
				dbUserMessage.SetStatus(ReadStatus.Readed);
				dbUserMessage.UpdateToDb();
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.Rows.Count > 0)
			{
				List<DataGridViewRow> list = new List<DataGridViewRow>();
				List<DbUserMessage> list2 = new List<DbUserMessage>();
				foreach (object obj in ((IEnumerable)this.dataGridView1.Rows))
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					if ((bool)dataGridViewRow.Cells["Remove"].Value)
					{
						list.Add(dataGridViewRow);
						DbUserMessage dbMessage = DbUserMessage.GetDbMessage(Convert.ToInt32(dataGridViewRow.Cells["Id"].Value), BimServerDB.Default);
						if (dbMessage != null)
						{
							list2.Add(dbMessage);
						}
					}
				}
				if (list.Count > 0)
				{
					if (MessageBox.Show("是否将选中的信息删除？", "项目管理器", MessageBoxButtons.YesNo) != DialogResult.Yes)
					{
						return;
					}
					foreach (DataGridViewRow dataGridViewRow2 in list)
					{
						this.dataGridView1.Rows.Remove(dataGridViewRow2);
					}
					using (List<DbUserMessage>.Enumerator enumerator3 = list2.GetEnumerator())
					{
						while (enumerator3.MoveNext())
						{
							DbUserMessage dbUserMessage = enumerator3.Current;
							dbUserMessage.RemoveFromDb();
						}
						return;
					}
				}
				MessageBox.Show("没有选中任何信息。");
			}
		}

		private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
		{
		}

		private void DlgMessageBox_Load(object sender, EventArgs e)
		{
		}
	}
}
